package com.auto.sns.login.action;

import java.util.Map;

import com.auto.oa.user.domain.OaUserInfo;
import com.auto.oa.user.service.OaUserServiceFactory;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.system.common.BaseAction;
import com.system.util.BeanUtil;

public class SnsLoginAction extends BaseAction {
	
	private static final long serialVersionUID = -5946137321963058124L;
	private final static String PLAT_USERLABLE = "plat_userLable";
	
	public String userLogin() {
		try {
			
			String userCode = getRequest().getParameter("userCode");
			String password = getRequest().getParameter("password");
			
			OaUserInfo oaUserInfo = OaUserServiceFactory.oaUserInfoService.getOaUserInfoForLogin(userCode, password);
			if(BeanUtil.isObjectNull(oaUserInfo)){
				getRequest().setAttribute("loginError", "用户名或密码不正确");
				
				return Action.LOGIN;
			}else{
				Map<String, Object> sessionMap = ActionContext.getContext().getSession();
				sessionMap.put(PLAT_USERLABLE, userCode);
				
				return Action.SUCCESS;
			}
			
		} catch (Exception e) {
			e.printStackTrace();
			return Action.LOGIN;
		}
	}
	
	public String userLogout() {
		try {
			Map<String, Object> sessionMap = ActionContext.getContext().getSession();
			sessionMap.remove(PLAT_USERLABLE);
			
			return Action.SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return Action.LOGIN;
		}
	}

}
